package com.gitee.wsl.ext.array

import com.gitee.wsl.ext.list.timesToListOf

fun DoubleArray(vararg values:Double) = values

 fun IntArray(vararg values:Int) = values

 fun FloatArray(vararg values:Float) = values


fun combineToByteArray(vararg elements: Any): ByteArray {
 val totalSize = elements.sumOf { element ->
  when (element) {
   is ByteArray -> element.size
   is Byte -> 1
   else -> throw IllegalArgumentException("Unsupported type: ${element::class.simpleName}")
  }
 }

 val result = ByteArray(totalSize)
 var offset = 0

 elements.forEach { element ->
  when (element) {
   is ByteArray -> {
    element.copyInto(result, offset)
    offset += element.size
   }

   is Byte -> {
    result[offset] = element
    offset++
   }
  }
 }

 return result
}

inline fun <reified T> Int.timesToArrayOf(predicate: (Int) -> T) = timesToListOf(predicate).toTypedArray()
